import oss2
from apps.common.ali import setting
import datetime
from apps.system.lessee.dao import LesseeDao
def get_bucket():
    filePath = str(datetime.datetime.now().year) + '/' + str(datetime.datetime.now().month) + '/' + str(datetime.datetime.now().day) + '/'
    #********************赛拉米********************/
    bucket = None
    baseImgUrl = ''
    _lessee = LesseeDao().getLessee()
    if _lessee.uploadFileCHN == 'xlsh':
        # 阿里云账号AccessKey拥有所有API的访问权限，风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维，请登录RAM控制台创建RAM用户。
        auth = oss2.Auth(setting.config.get('xlsh').get('ACCESS_KEY_ID'), setting.config.get('xlsh').get('ACCESS_KEY_SECRET'))
        # yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1（杭州）为例，Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
        endpoint = 'https://oss-cn-shanghai.aliyuncs.com'
        # 填写Bucket名称。
        bucket = oss2.Bucket(auth, endpoint, 'xlsh-first')                    
        baseImgUrl = 'https://oss.sailami.top/'
    elif _lessee.uploadFileCHN == 'qlw':
        #********************千里坞********************/
        auth = oss2.Auth(setting.config.get(_lessee.uploadFileCHN).get('ACCESS_KEY_ID'), setting.config.get(_lessee.uploadFileCHN).get('ACCESS_KEY_SECRET'))
        endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
        bucket = oss2.Bucket(auth, endpoint, 'qly-bucket')                    
        baseImgUrl = 'https://oss.qly.plus/'
    elif _lessee.uploadFileCHN == 'zjyh':
        #********************正金壹号********************/
        auth_zjyh = oss2.Auth(setting.config.get('zjyh').get('ACCESS_KEY_ID'), setting.config.get('zjyh').get('ACCESS_KEY_SECRET'))
        endpoint_zjyh = 'https://oss-cn-hangzhou.aliyuncs.com'
        bucket_zjyh = oss2.Bucket(auth_zjyh, endpoint_zjyh, 'zjyh-first')
        baseImgUrl_zjyh = 'https://oss.zjyh888.com/'
    elif _lessee.uploadFileCHN == 'xlmp':
        #********************鑫珑名品********************/
        auth = oss2.Auth(setting.config.get(_lessee.uploadFileCHN).get('ACCESS_KEY_ID'), setting.config.get(_lessee.uploadFileCHN).get('ACCESS_KEY_SECRET'))
        endpoint = 'https://oss-cn-shanghai.aliyuncs.com'
        bucket = oss2.Bucket(auth, endpoint, 'xlmp-bucket')
        baseImgUrl = 'https://xlmp.oss.qly.plus/'
    return {
        'bucket': bucket,
        'baseImgUrl': baseImgUrl,
        'filePath': filePath
    }

